C
C             A S Y M P T O T I C        F - T E S T
C
C     OBJECTIVE : perform an F significativity test for many
C     ---------   degrees of freedom.
C
C     REFERENCES : the asymptotic formula 26.6.13 from Abramowitz &
C     ----------   Stegun is used. The expression for the Gauss
C                  integral that is needed is 26.2.17 (ibid.).
C
C     [AM, in a beautiful Sunday afternoon in March 1986]
C
c     trasformata in subroutine da F.Mele - 9 dec '94
      subroutine Ftest(nobs,var1,npar1,var2,npar2,qtot,signif)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
c      write(*,'(20X,'' A S Y M P T O T I C     F - T E S T''/
c     >          20X,'' (valid for many degrees of freedom)''//)')
c      write(*,'('' Type number of observations : '',$)')
c      read(*,*)NOBS
c      write(*,'(''         Type var1 and npar1 : '',$)')
c      read(*,*)VAR1,NPAR1
c      write(*,'(''         Type var2 and npar2 : '',$)')
c      read(*,*)VAR2,NPAR2
      RNU1=NOBS-NPAR1
      RNU2=NOBS-NPAR2
      F=(VAR1/VAR2)*(RNU2/RNU1)
      X=        ( F - RNU2/(RNU2-2.D0) )  /
     >((RNU2/(RNU2-2.))*DSQRT(2.D0*(RNU1+RNU2-2.D0)/(RNU1*(RNU2-4.))))
      QTOT=Q(X)
c      write(*,*)' (probability is ',QTOT,')'
      SIGNIF=(1.-QTOT)*100.
c      write(*,'(/20X,'' improvement significant to '',F7.2,'' % '')')
c     > SIGNIF
      return
      END

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

      DOUBLE PRECISION FUNCTION Q(X)
C
C     polynomial expansion from Abr. & Steg., 26.2.17
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      DATA     P/.2316419D0/, B1/.319381530D0/,   B2/-.356563782D0/,
     >     B3/1.781477937D0/, B4/-1.821255978D0/, B5/1.330274429D0/
      Z(Y)=DEXP(-Y*Y/2.)/SQR2PI
C
      SQR2PI=DSQRT(2.D0*DACOS(-1.D0))
      T=1./(1.+P*X)
      T2=T*T
      T3=T2*T
      T4=T3*T
      T5=T4*T
      POLY=B1*T + B2*T2 + B3*T3 + B4*T4 + B5*T5
      Q=Z(X)*POLY
C
      RETURN
      END

